
/*
 * -- SuperLU MT routine (version 2.0) --
 * Lawrence Berkeley National Lab, Univ. of California Berkeley,
 * and Xerox Palo Alto Research Center.
 * September 10, 2007
 *
 * Sparse matrix types and function prototypes.
 *
 */

#ifndef __SUPERLU_dSP_DEFS /* allow multiple inclusions */
#define __SUPERLU_dSP_DEFS

/*
 * File name:           pdsp_defs.h
 * Purpose:             Sparse matrix types and function prototypes
 * History:
 */

#include "hnum_slucmn.h"


namespace harlinn
{
    namespace numerics
    {
        namespace SuperLU
        {
            namespace Double
            {

                typedef GlobalLU_T<double> GlobalLU_t;
                typedef pxgstrf_shared_T<GlobalLU_t> pxgstrf_shared_t;
                typedef pxgstrf_threadarg_T<pxgstrf_shared_t> pdgstrf_threadarg_t;


                /* *********************
                   Function prototypes
                   *********************/


                /* ----------------
                   Driver routines 
                   ---------------*/
                void pdgssv(int, SuperMatrix *, int *, int *, SuperMatrix *, SuperMatrix *, SuperMatrix *, int *);
                void pdgssvx(int, superlumt_options_t *, SuperMatrix *, int *, int *,  
	                                equed_t *, double *, double *, SuperMatrix *, SuperMatrix *,
	                                SuperMatrix *, SuperMatrix *, 
	                                double *, double *, double *, double *, superlu_memusage_t *, 
	                                int *);

                /* ---------------
                   Driver related 
                   ---------------*/
                void dgsequ (SuperMatrix *, double *, double *, double *,double *, double *, int *);
                void dlaqgs (SuperMatrix *, double *, double *, double, double, double, equed_t *);
                void dgscon (char *, SuperMatrix *, SuperMatrix *,double, double *, int *);
                double dPivotGrowth(int, SuperMatrix *, int *,SuperMatrix *, SuperMatrix *);
                void dgsrfs (trans_t, SuperMatrix *, SuperMatrix *, SuperMatrix *,int *, int *, equed_t, double *, double *, SuperMatrix *,SuperMatrix *, double *, double *, Gstat_t *, int *);
                int  sp_dtrsv (char *, char *, char *, SuperMatrix *, SuperMatrix *,double *, int *);
                int  sp_dgemv (char *, double, SuperMatrix *, double *,int, double, double *, int);
                int  sp_dgemm (char *, int, int, int, double, SuperMatrix *, double *, int, double, double *, int);

                /* ----------------------
                   Factorization related
                   ----------------------*/

                void dCreate_CompCol_Matrix(SuperMatrix *, int, int, int, double *,
		                      int *, int *, Stype_t, Dtype_t, Mtype_t);
                void dCreate_CompCol_Permuted(SuperMatrix *, int, int, int, double *, int *, int *, int *, Stype_t, Dtype_t, Mtype_t);
                void dCopy_CompCol_Matrix(SuperMatrix *, SuperMatrix *);
                void dCreate_Dense_Matrix(SuperMatrix *, int, int, double *, int, Stype_t, Dtype_t, Mtype_t);
                void dCreate_SuperNode_Matrix(SuperMatrix *, int, int, int, double *, int *, int *, int *, int *, int *, Stype_t, Dtype_t, Mtype_t);
                void dCreate_SuperNode_Permuted(SuperMatrix *, int, int, int, double *, 
			                   int *, int *, int *, int *, int *, int *, 
			                   int *, int *, Stype_t, Dtype_t, Mtype_t);
                void dCopy_Dense_Matrix(int, int, double *, int, double *, int);

                void dallocateA (int, int, double **, int **, int **);
                void get_perm_c(int, SuperMatrix *, int *);
                void dsp_colorder (SuperMatrix *, int *, superlumt_options_t *,
			                 SuperMatrix *);
                int  dPresetMap (const int, SuperMatrix *, pxgstrf_relax_t *, 
		                       superlumt_options_t *, GlobalLU_t *);
                int  DynamicSetMap(const int, const int, const int, pxgstrf_shared_t*);
                void pdgstrf (superlumt_options_t *, SuperMatrix *, int *, 
		                     SuperMatrix *, SuperMatrix *, Gstat_t *, int *);
                void pdgstrf_init (int, fact_t, trans_t, yes_no_t, int, int, double, yes_no_t, double,
			                  int *, int *, void *, int, SuperMatrix *,
			                  SuperMatrix *, superlumt_options_t *, Gstat_t *);
                pdgstrf_threadarg_t* pdgstrf_thread_init (SuperMatrix *, SuperMatrix *, SuperMatrix *,
		                                superlumt_options_t*, pxgstrf_shared_t*, Gstat_t*, int*);
                void pdgstrf_thread_finalize (pdgstrf_threadarg_t *, pxgstrf_shared_t *,
			                 SuperMatrix *, int *, SuperMatrix *, SuperMatrix *);
                void pdgstrf_finalize(superlumt_options_t *, SuperMatrix *);
                int pdgstrf_factor_snode (const int, const int, SuperMatrix *, const double,
		                      yes_no_t *, int *, int *, int*, int*, int*, int*,
		                      double *, double *, pxgstrf_shared_t *, int *);
                void pdgstrf_mark_busy_descends (int, int, int *, pxgstrf_shared_t *, int *, int *);
                int  pdgstrf_snode_dfs (const int, const int, const int, const int *,
			                       const int *, const int *, int*, int *, int *,
			                       pxgstrf_shared_t *);
                int  pdgstrf_snode_bmod (const int, const int, const int, const int,
				                double *, double *, GlobalLU_t*, Gstat_t*);
                void pdgstrf_panel_dfs (const int, const int, const int, const int,
			                       SuperMatrix *, int*, int*, int*, int*, int*, 
			                       int*, int*, int*, int*, int*, int*, int*, int*,
			                       double*, GlobalLU_t *);
                void pdgstrf_panel_bmod (const int, const int, const int, const int,
				                const int, int*, int*, int*, int*, int*, int*,
				                int*, int*, double*, double*, 
				                pxgstrf_shared_t *);
                void pdgstrf_bmod1D (const int, const int, const int, const int, 
			                    const int, const int, const int, int, int,
			                    int *, int *, int *, int *, double *, double *, 
			                    GlobalLU_t *, Gstat_t *);
                void pdgstrf_bmod2D (const int, const int, const int, const int,
			                    const int, const int, const int, int, int,
			                    int *, int *, int *, int *, double *, double *,
			                    GlobalLU_t *, Gstat_t *);
#ifndef _MSC_VER
                void pdgstrf_bmod1D_mv2 (const int, const int, const int, const int, 
				                const int, const int, const int, int, int,
				                int *, int *, int *, int *, double *, 
				                double *, GlobalLU_t *, Gstat_t *);
                void pdgstrf_bmod2D_mv2 (const int, const int, const int, const int,
				                const int, const int, const int, int, int,
				                int *, int *, int *, int *, double *, double *,
				                GlobalLU_t *, Gstat_t *);
#endif
                int  pdgstrf_column_dfs(const int, const int, const int, const int,
			                       int*, int*, int*, int, int*, int*, int*, int*,
			                       int *, int *, int *, int *, pxgstrf_shared_t *);
                int  pdgstrf_column_bmod(const int, const int, const int, const int, 
				                int*, int*, double*, double*,
				                pxgstrf_shared_t *, Gstat_t *);
                int  pdgstrf_pivotL (const int, const int, const double, yes_no_t*,
			                    int*, int*, int*, int*, GlobalLU_t*, Gstat_t*);
                int  pdgstrf_copy_to_ucol (const int, const int, const int, const int *,
				                  const int *, const int *, double*,
				                  pxgstrf_shared_t*);
                void pdgstrf_pruneL (const int, const int *, const int, const int,
			                    const int *, const int *, int*, int *,
			                    GlobalLU_t *);
                void compressSUP (const int, GlobalLU_t *);
                void dreadmt (int *, int *, int *, double **, int **, int **);
                void dreadhb (int *, int *, int *, double **, int **, int **);
                void dGenXtrue (int, int, double *, int);
                void dFillRHS (trans_t, int, double *, int, 
		                      SuperMatrix *, SuperMatrix *);
                void dgstrs (trans_t, SuperMatrix *, SuperMatrix*, int*, int*, SuperMatrix*, Gstat_t *, int *);


                /* ---------------
                   Memory related 
                   ---------------*/
                float pdgstrf_MemInit (int, int, superlumt_options_t *,
			                SuperMatrix *, SuperMatrix *, GlobalLU_t *);
                float pdgstrf_memory_use(const int, const int, const int);
                int  pdgstrf_WorkInit (int, int, int **, double **);
                void pdgstrf_SetRWork (int, int, double *, double **, double **);
                void pdgstrf_WorkFree (int *, double *, GlobalLU_t *);
                int  pdgstrf_MemXpand (int, int, MemType, int *, GlobalLU_t *);

                
                double *doubleMalloc(int);
                double *doubleCalloc(int);
                int  memory_usage ();
                int  superlu_dQuerySpace (int, SuperMatrix *, SuperMatrix *, int,  superlu_memusage_t *);
                int  Glu_alloc (const int, const int, const int, const MemType, int *, pxgstrf_shared_t *);

                /* -------------------
                   Auxiliary routines
                   -------------------*/
                void    dfill(double *, int, double);
                void    dinf_norm_error(int, SuperMatrix *, double *);
                void    snode_profile(int, int *);
                void    super_stats(int, int *, int *);
                void    panel_stats(int, int, int *, Gstat_t *);
                void    PrintSumm(char *, int, int, int);
                void    dPrintPerf(SuperMatrix *, SuperMatrix *, superlu_memusage_t *, double, double, double *, double *, char *, Gstat_t *);
                void    dCompRow_to_CompCol(int m, int n, int nnz,  double *a, int *colind, int *rowptr, double **at, int **rowind, int **colptr);


                /* -----------------------
                   Routines for debugging
                   -----------------------*/
                void    print_lu_col(int, char *, int, int, int, int *, GlobalLU_t *);
                void    print_panel_seg(int, int, int, int, int *, int *);
                void    dcheck_zero_vec(int, char *, int, double *);
                void    check_repfnz(int, int, int, int *);

                void *pdgstrf_thread(void *arg);




            };
        };
    };
};


#endif /* __SUPERLU_DSP_DEFS */

